##! /bin/bash
#! bash
#
#  $Id: files.sh 3 2010-05-27 16:25:49Z alistair.mills@btinternet.com $
#
#set -x
export TARGET='Articles de La Guinguette &agrave; traduire'

. ./defines.sh

### Main script stars here ###
# Store file name  here
FILE=$1
  . ./defines.sh
  . ./keys.sh

while read year mon cat size url key trans line
do
  if [ "$line" != "$title_line" -a "$year" != "$comment_line" ]
  then
  . ./months.sh
  . ./translators.sh
  . ./categories.sh
  export      tra=${year}_${mon}_${cat}
  export     item=${year}${mon}${cat}
  export    INPUT=${year}_${mon}_${cat}.htm
  export   OUTPUT=${year}_${mon}_${cat}.html
  export OUTPUT_1=${OUTPUT}_1
  export OUTPUT_2=${OUTPUT}_2

  if [ "$line" != "" -a \( "$key" = "$done" -o "$key" = "$in_progress" -o "$key" = "$not_started" \) ]
  then
    [ -f       $INPUT ] || touch                  $INPUT
    [ -f  $last$INPUT ] || echo $date >      $last$INPUT
    [ -f $key_d$INPUT ] || echo $key_date > $key_d$INPUT
    echo Found: $INPUT - $line
    export change_date=`cat  $last$INPUT`
    export  change_key=`cat $key_d$INPUT`

    cat > ${OUTPUT_1} <</eof

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta name="description" content="French Lessons">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<title>Articles de La Guinguette - $year - $month - $category</title>
           <link href="../../style.css" rel="stylesheet" type="text/css">

<style type="text/css">
p {
    color: Black;
}
</style>

</head>

<body bgcolor="#FFFFFF" background="../back.gif" text="#008000" link="#0000FF" vlink="#0000FF">

<a href="index.html"><img src="../../up.gif" alt="up" width="36" height="18"></a><br>

<h1>Articles de La Guinguette - $year - $month - $category</h1>

<table border="1">
<tr><td>Titre</td>                             <td>$line          </td></tr>
<tr><td>Ann&eacute;e</td>                      <td>$year          </td></tr>
<tr><td>Mois</td>                              <td>$month         </td></tr>
<tr><td>Cat&eacute;gorie</td>                  <td>$category      </td></tr>
<tr><td>Traducteur</td>                        <td>$translator</td></tr>
<tr><td>Derni&egrave;re mise &agrave; jour</td><td>$change_date</td></tr>
</table>
<br>
<a title="chercher" href="_zoom/search.php">Chercher les articles</a><br>
<br>

<hr>

/eof
fi

if [ "$line" != "" -a \( "$key" = "$done" -o "$key" = "$in_progress" -o "$key" = "$not_started" \) -a -f $INPUT ]
then
  cat           > ${OUTPUT_2} <</eof

<hr>
<h1>Notes</h1>
<p>With questions or for more information, please contact Alistair Mills (<a href="mailto:alistair.mills@btinternet.com">alistair.mills@btinternet.com</a>)<br>
Updated $change_date</p>


    <a href="http://validator.w3.org/check?uri=referer"><img
        src="http://www.w3.org/Icons/valid-html401-blue"
        alt="Valid HTML 4.01 Transitional" height="31" width="88"></a>

<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-2273668-1";
urchinTracker();
</script>


</body>
</html>
/eof
fi

if [ -f ${OUTPUT_1}                -a -f ${OUTPUT_2} ]
then
  cat   ${OUTPUT_1}       ${INPUT}       ${OUTPUT_2} > $OUTPUT
  rm    ${OUTPUT_1}                      ${OUTPUT_2}
  touch -r                ${INPUT}                    ${OUTPUT}
fi
fi
done < $FILE

#
#
#

